package com.ubb.dbms.core.connection;


import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ubb.dbms.core.connection.result.MessageResult;
import com.ubb.dbms.core.parser.QueryParser;
import com.ubb.dbms.core.parser.SQLQueryParser;

public class ServerHandler extends IoHandlerAdapter {
	private final Logger log = LoggerFactory.getLogger(ServerHandler.class);
	private static final QueryParser sqlQueryParser = new SQLQueryParser();
	
	@Override
	public void messageReceived(IoSession session, Object message)
	{
		log.info("Message received in the server : " + message.toString());
		
		MessageResult.setMessage(new JSONObject());
		sqlQueryParser.commit(message.toString());
    	session.write(MessageResult.getMessage());

	}
}
